# -*- coding: utf-8 -*-
# @Time    : 2022/3/21 11:49
# @Author  : Zhy
# @Email   : mat_wu@163.com
# @File    : __init__.py.py
# @Software: PyCharm

from common.models import db, cache
from flask import Flask
from flask_cors import CORS
from second_flask.resources.exports import stu_bp
from common.utils.middleware import jwt_authenrization
from second_flask.resources.goods import shop_bp
from second_flask.resources.plant import plant_bp
from second_flask.resources.user import user_bp
from second_flask.resources.message import message_bp
from second_flask.resources.check_message import check_message_bp
from second_flask.resources.goods_info import goods_info_bp
from second_flask.resources.carts import carts_bp
from second_flask.resources.statistics import statistics_bp


def create_flask_app(config):
    app = Flask(__name__)
    app.config.from_object(config)
    db.init_app(app)
    cache.init_app(app)
    app.register_blueprint(stu_bp)
    app.register_blueprint(shop_bp)
    app.register_blueprint(plant_bp)
    app.register_blueprint(user_bp)
    app.register_blueprint(message_bp)
    app.register_blueprint(check_message_bp)
    app.register_blueprint(goods_info_bp)
    app.register_blueprint(statistics_bp)
    app.register_blueprint(carts_bp)
    app.before_request(jwt_authenrization)
    cors = CORS(app, resource={r'/api/*': {'origins': '*'}})
    return app
